<?php
/******************************************************
v4 - Management Framework
Copyright (C) 2008  Gary Taylor, gMerc Incorporation
http://www.gmerc.com/v4/

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.

gary@gmerc.com
******************************************************/
class authorizedotnet {
  function send_transaction($fields) {
    global $masterclass;
      
        
    $ch = curl_init($masterclass->websiteconfig['authorizedotnet_transactionurl']='https://test.authorize.net/gateway/transact.dll'); 
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, rtrim( $fields, "& " ));
    ### curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // uncomment this line if you get no gateway response. ###
    $resp = curl_exec($ch);
    curl_close ($ch);

  return $resp;
  }
  
  function validate_fields($fields) {
    if (!is_array($fields) || empty($fields) { return false; }
    $required=array('x_login','x_tran_key','x_version');
    
    foreach ($required as $key) {
      if ($fields[$key]=='') { $err .= "No $key\n"; }
    }
   
  if ($err!='') { return $err; } else { return 'validated'; }  
  }
  
  function fetch_transactionfields($staticfields=array()) {
    global $masterclass;
    
    $websitefields=array('x_version','x_delim_char','x_delim_data','x_url');
    $sitefields=array('x_login','x_tran_key');
    
    foreach ($websitefields as $key) {
      if (!in_array($key,$staticfields)) { $staticfields[$key]=$masterclass->websiteconfig['authorizedotnet_defaultfield_'.$key]; }
    }
    foreach ($sitefields as $key) {
      if (!in_array($key,$staticfields)) { $staticfields[$key]=$masterclass->site['authorizedotnet_'.$key]; }
    }
    
  return $staticfields;
  }
}
?>